package com.hxq.library.service.Impl;

import com.hxq.library.dao.IUserDao;
import com.hxq.library.dao.impl.UserDaoImpl;
import com.hxq.library.entity.User;
import com.hxq.library.service.IUserService;
import com.hxq.library.utils.JavaDateConnection;

import java.sql.SQLException;

/**
 * @Author: Ljx
 * @Date: 2021/11/24 13:29
 * @role:
 */
public class UserService implements IUserService {

    IUserDao userDao = new UserDaoImpl();
    JavaDateConnection javaDateConnection = new JavaDateConnection();
    @Override
    public boolean login(User user) throws SQLException {
        boolean login = userDao.login(javaDateConnection.getConn(), user);
        if (login){
            return true;
        }else {
            return false;
        }
    }

    @Override
    public boolean register(String account, String password) {
        boolean register = userDao.register(javaDateConnection.getConn(), account, password);
        if (register){
            return true;
        }else {
            return false;
        }
    }

    @Override
    public boolean pay(int money, String account, String password, String number) throws SQLException {
        boolean pay = userDao.pay(javaDateConnection.getConn(), money, account, password, number);
        if (pay){
            return true;
        }
        return false;
    }

    @Override
    public int selectMoney(String account) throws SQLException {
        int money = userDao.selectMoney(javaDateConnection.getConn(), account);
        return money;
    }

    @Override
    public int payVip(String account) throws SQLException {
        int payVip = userDao.payVip(javaDateConnection.getConn(), account);
        return payVip;
    }

    @Override
    public int selectVip(String account) throws SQLException {
        int vip = userDao.selectVip(javaDateConnection.getConn(), account);
        return vip;
    }

    @Override
    public boolean changePassword(String account, String oldPassword, String password) throws SQLException {
        boolean changePassword = userDao.changePassword(javaDateConnection.getConn(), account, oldPassword, password);
        return changePassword;
    }

    @Override
    public boolean forgetPassword(String account, String number, String code) throws SQLException {
        boolean forgetPassword = userDao.forgetPassword(javaDateConnection.getConn(), account, number, code);
        return forgetPassword;
    }

    @Override
    public boolean changePassword(String account, String newPassword) throws SQLException {
        boolean changePassword = userDao.changePassword(javaDateConnection.getConn(), account, newPassword);
        return changePassword;
    }

    @Override
    public boolean selectUser(String account) throws SQLException {
        boolean selectUser = userDao.selectUser(javaDateConnection.getConn(), account);
        return selectUser;
    }
}
